import React from 'react';
import { Modal, Form, Input, Button, Icon, message, Spin, TreeSelect, Checkbox, Select } from 'antd';
import { history } from 'umi'
import { connect } from 'umi';
// import moment from 'moment';
import { debounce } from 'lodash';
import BraftEditor from 'braft-editor';
import 'braft-editor/dist/index.css';
import { customUpload } from '@/utils/fileUpload';
import QuickTaskBar from '../QuickTaskBar';
import ChildTask from '../ChildTask';
import TipBox from '../TipBox';
import TaskListItem from '../TaskListItem';
import styles from './index.less';
import {
    getEmployeeList,
    launchTask,
    getActionTaskInfo,
    getActionTaskInfoSimple,
    updateTask,
    createSubTask,
    restartTask,
    copyTask,
    searchParentTask,
    changeParentTaskCheck
} from '../../services';
import { refreshTaskCount, TaskStatus } from '../../utils';
import { showTipBoxInfoModal } from '../../MyTask/containers/MyTaskInfoModal';

const { confirm } = Modal;
const { Option } = Select;

const getEmployeeCode = () => {
    const user = localStorage.getItem('user');
    if (user) {
        const { employeeCode = '' } = JSON.parse(user);
        return employeeCode;
    }
    return '';
};

// 不允许添加尺寸大于10M的文件
const myValidateFn = file => {
    if (file.size > 1024 * 1024 * 10) {
        message.error('图片不能大于10M！');
        return false;
    }
    return true;
};

const getEmployeeName = (val, list = []) => {
    const arr = list.filter(item => item.value === val);
    if (arr && arr.length > 0) {
        return arr[0].employeeName || '';
    }
    return '';
};

const StartTaskModal = ({ form, visible, setVisible, type, record, onOk, onCancel, dispatch }) => {
    const user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {};
    const { getFieldDecorator } = form;
    const [loading, setLoading] = React.useState(false);
    const [confirmLoading, setConfirmLoading] = React.useState(false);
    const [taskName, setTaskName] = React.useState('');
    const [participantEmployeeList, setParticipantEmployeeList] = React.useState([]);
    const [taskObj, setTaskObj] = React.useState({
        executeEmployeeCode: getEmployeeCode() || '',
        planStartTime: '',
        planEndTime: '',
        taskPriority: 1,
        auditEmployeeCode: '',
        acceptanceEmployeeCode: ''
    });
    const [taskDesc, setTaskDesc] = React.useState('');
    const [childList, setChildList] = React.useState([]);
    const [isCheck, setIsCheck] = React.useState(false);
    const [isMore, setIsMore] = React.useState(false);
    const [employeeList, setEmployeeList] = React.useState([]);
    const [taskDetail, setTaskDetail] = React.useState(null);
    const editorRef = React.useRef(null);
    const [parentTaskList, setParentTaskList] = React.useState([]);
    const [parentTaskId, setParentTaskId] = React.useState();
    const [enableChildren, setEnableChildren] = React.useState(0);

    const submitTip = () => {
        const { auditEmployeeCode } = taskObj;
        if (auditEmployeeCode) {
            const auditEmployeeName = getEmployeeName(auditEmployeeCode, employeeList);
            confirm({
                title: '提示',
                content: (
                    <>
                        <TipBox
                            title="提交成功！"
                            content={
                                <>
                                    <div style={{ textAlign: 'center' }}>
                                        需待审核人【{auditEmployeeName || ''}】审核通过后
                                    </div>
                                    <div style={{ textAlign: 'center' }}>系统方可指派给执行人</div>
                                </>
                            }
                        />
                        <TipBox content="请至“我发起的”列表查看已发起的任务" />
                    </>
                ),
                className: styles.confirmModal
            });
        } else {
            showTipBoxInfoModal({
                title: '提示',
                rows: ['提交成功！', '请至“我发起的”列表查看已发起的任务！']
            });
        }
    };

    const handleAddTask = async params => {
        setConfirmLoading(true);
        const res = await launchTask(params);
        if (res && res.code === 10000) {
            // console.log(res);
            if (onOk) onOk();
            setConfirmLoading(false);
            submitTip();
            setVisible(false);
            refreshTaskCount(dispatch);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleCopyTask = async params => {
        setConfirmLoading(true);
        const res = await copyTask(params);
        if (res && res.code === 10000) {
            // console.log(res);
            if (onOk) onOk();
            setConfirmLoading(false);
            submitTip();
            setVisible(false);
            refreshTaskCount(dispatch);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleUpdateTask = async params => {
        setConfirmLoading(true);
        const res = await updateTask(params);
        if (res && res.code === 10000) {
            // console.log(res);
            if (onOk) onOk();
            setConfirmLoading(false);
            // submitTip();
            setVisible(false);
            refreshTaskCount(dispatch);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleUpdateParentTaskCheck = async params => {
        setConfirmLoading(true);
        const res = await changeParentTaskCheck(params);
        const { code, data } = res;
        if (code === 10000) {
            if (data) {
                const { taskStatus, inAuditFlag, operateName, inAcceptanceFlag } = data;
                let nowStatus = '';
                if (taskStatus === TaskStatus.CANCEL) {
                    nowStatus = '已取消';
                } else if (taskStatus === TaskStatus.FINISH) {
                    nowStatus = '已完成';
                } else if (inAuditFlag) {
                    nowStatus = `${operateName}待审核`;
                } else if (inAcceptanceFlag) {
                    nowStatus = '待验收';
                }
                if (nowStatus) {
                    message.error(`所选的上一级任务已更新状态为${nowStatus}，不允许提交！`);
                    setConfirmLoading(false);
                    return;
                }
            }
            handleUpdateTask(params);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleCreateSubTask = async params => {
        setConfirmLoading(true);
        const res = await createSubTask(params);
        if (res && res.code === 10000) {
            // console.log(res);
            if (onOk) onOk();
            setConfirmLoading(false);
            submitTip();
            setVisible(false);
            refreshTaskCount(dispatch);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleRestartTask = async params => {
        setConfirmLoading(true);
        const res = await restartTask(params);
        if (res && res.code === 10000) {
            // console.log(res);
            if (onOk) onOk();
            setConfirmLoading(false);
            submitTip();
            setVisible(false);
            refreshTaskCount(dispatch);
        } else {
            setConfirmLoading(false);
        }
    };

    const handleNameChange = e => {
        setTaskName(e.target.value);
    };

    const handleOk = () => {
        setIsCheck(true);
        form.validateFields((err, values) => {
            if (err) {
                return;
            }
            if (taskDesc.length > 20000) {
                message.error('任务描述内容过多');
                return;
            }
            const {
                executeEmployeeCode,
                planEndTime,
                taskPriority,
                auditEmployeeCode,
                acceptanceEmployeeCode
            } = taskObj;
            const arrTemp = childList.filter(
                item => item.taskName && item.executeEmployeeCode && item.planEndTime && item.taskPriority
            );
            if (executeEmployeeCode && planEndTime && taskPriority && arrTemp.length >= childList.length) {
                if (type) {
                    const { personalPrivacyFlag = 0 } = taskDetail;
                    if (personalPrivacyFlag) {
                        if (
                            auditEmployeeCode ||
                            acceptanceEmployeeCode ||
                            (participantEmployeeList && participantEmployeeList.length > 0)
                        ) {
                            message.error('该任务为隐私任务，不可填写审核人、验收人或参与人');
                            return;
                        }
                        const arrTemp3 = childList.filter(
                            item =>
                                item.auditEmployeeCode ||
                                item.acceptanceEmployeeCode ||
                                (item.participantEmployeeCodeList && item.participantEmployeeCodeList.length > 0)
                        );
                        if (arrTemp3.length > 0) {
                            message.error('该任务为隐私任务，不可填写审核人、验收人或参与人');
                            return;
                        }
                    }
                }
                if (auditEmployeeCode) {
                    const arrTemp2 = childList.filter(item => item.auditEmployeeCode);
                    if (arrTemp2.length < childList.length) {
                        message.error('当前任务已选审核人，批量新增的子任务也需选择审核人');
                        return;
                    }
                }
                // if (
                //     taskDetail &&
                //     taskDetail.parentPlanEndTime &&
                //     moment(planEndTime).isAfter(taskDetail.parentPlanEndTime)
                // ) {
                //     const str = moment(taskDetail.parentPlanEndTime).format(
                //         taskDetail.parentPlanEndTime.indexOf('23:59:59') !== -1 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm'
                //     );
                //     message.error(`不可大于上级任务截止时间${str}`);
                //     return;
                // }
                // if (planEndTime && childList.length > 0) {
                //     let tempFlag = false;
                //     childList.forEach(item => {
                //         if (moment(item.planEndTime).isAfter(planEndTime)) {
                //             tempFlag = true;
                //         }
                //     });
                //     if (tempFlag) {
                //         const str = moment(planEndTime).format(
                //             planEndTime.indexOf('23:59:59') !== -1 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm'
                //         );
                //         message.error(`不可大于上级任务截止时间${str}`);
                //         return;
                //     }
                // }
                const params = {
                    ...taskDetail,
                    ...values,
                    taskName: taskName.trim(),
                    participantEmployeeCodeList: participantEmployeeList,
                    taskDesc,
                    ...taskObj,
                    subtaskList: childList,
                    enableChildrenQueryFlag: values.enableChildrenQueryFlag ? 1 : 0
                };
                if (type === 'change_task') {
                    // 如果有选择上一级任务，就改变父任务id和name传给后端
                    if (values.parentTaskId) {
                        const filterList = parentTaskList.filter(item => item.taskId === values.parentTaskId);
                        params.parentTaskId = values.parentTaskId;
                        params.parentTaskName = filterList && filterList.length > 0 ? filterList[0].taskName : '';
                        // const tempTime = filterList && filterList.length > 0 ? filterList[0].planEndTime : '';
                        // if (tempTime && moment(planEndTime).isAfter(tempTime)) {
                        //     const str = moment(tempTime).format(
                        //         tempTime.indexOf('23:59:59') !== -1 ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm'
                        //     );
                        //     message.error(`当前截止时间不可大于上一级任务截止时间${str}`);
                        //     return;
                        // }
                        if (taskDetail && taskDetail.parentTaskId) {
                            handleUpdateParentTaskCheck(params);
                            return;
                        }
                    }
                    handleUpdateTask(params);
                    return;
                }
                if (type === 'new_child_task') {
                    params.parentTaskId = record.id;
                    handleCreateSubTask(params);
                    return;
                }
                if (type === 'restart_task') {
                    handleRestartTask(params);
                    return;
                }
                if (type === 'copy_task') {
                    handleCopyTask(params);
                    return;
                }
                handleAddTask(params);
            }
        });
    };

    const handleCancel = () => {
        const {
            executeEmployeeCode,
            planStartTime,
            planEndTime,
            taskPriority,
            auditEmployeeCode,
            acceptanceEmployeeCode
        } = taskObj;
        if (
            taskName ||
            participantEmployeeList.length > 0 ||
            (taskDesc && taskDesc !== '<p></p>') ||
            (executeEmployeeCode && executeEmployeeCode !== getEmployeeCode()) ||
            planStartTime ||
            planEndTime ||
            taskPriority !== 1 ||
            auditEmployeeCode ||
            acceptanceEmployeeCode ||
            childList.length > 0
        ) {
            confirm({
                title: '确定需取消？',
                okText: '确定',
                cancelText: '取消',
                onOk() {
                    if (onCancel) onCancel();
                    setVisible(false);
                }
            });
        } else {
            if (onCancel) onCancel();
            setVisible(false);
        }
    };

    const handleTaskChange = value => {
        setTaskObj(value);
    };

    const handleChildListChange = list => {
        setChildList(list);
    };

    const getTitle = () => {
        switch (type) {
            case 'new_child_task':
                return '新增子任务';
            case 'change_task':
                return '变更任务';
            case 'copy_task':
                return '复制任务';
            case 'restart_task':
                return '重新发起';
            default:
                return '发起任务';
        }
    };
    const getEmployeeListAsync = async companyId => {
        const res = await getEmployeeList(companyId);
        if (res && res.code === 10000) {
            // console.log(res);
            const { data } = res;
            const arr = data.map(item => ({
                ...item,
                value: item.employeeCode,
                title: item.employeeName
            }));
            setEmployeeList(arr);
        }
    };
    const getParentTaskList = async (val = '') => {
        const res = await searchParentTask({
            parentTaskId: val.trim() ? undefined : (taskDetail && taskDetail.parentTaskId) || undefined,
            taskId: (record && record.id) || undefined,
            name: val || ''
        });
        if (res && res.code === 10000) {
            // console.log(res);
            const { data } = res;
            setParentTaskList(data);
        }
    };

    const handleMore = () => {
        setEnableChildren(form.getFieldValue('enableChildrenQueryFlag') ? 1 : 0);
        setParentTaskId(form.getFieldValue('parentTaskId') || (taskDetail && taskDetail.parentTaskId));
        setIsMore(true);
        setVisible(false);
    };

    const handleAfterClose = () => {
        if (isMore) {
            const taskParam = {
                ...taskDetail,
                parentTaskId,
                taskName,
                participantEmployeeCodeList: participantEmployeeList,
                taskDesc,
                ...taskObj,
                subtaskList: childList,
                enableChildrenQueryFlag: enableChildren
            };
            const key = new Date().getTime().toString();
            localStorage.setItem(
                key,
                JSON.stringify({
                    taskParam,
                    record
                })
            );
            history.push({
                pathname: '/work/task/addTask',
                query: {
                    key,
                    type
                },
                state: {
                    tabRoute: true,
                    tabRefresh: true
                }
            });
        }
    };

    const myUploadFn = param => {
        const onSuccess = (response, file) =>
            param.success({
                url: response.data[0].url,
                meta: {
                    id: file.name,
                    title: file.name,
                    alt: file.name
                }
            });
        customUpload({ files: param, onSuccess });
    };

    const handleEditorChange = editorState => {
        const html = editorState.toHTML();
        setTaskDesc(html);
        if (html.length > 20000) {
            message.error('任务描述内容过多');
        }
    };

    const getActionTaskDetail = async id => {
        setLoading(true);
        let res;
        if (type === 'change_task' || type === 'new_child_task') {
            res = await getActionTaskInfoSimple(id);
        } else {
            res = await getActionTaskInfo(id);
        }
        setLoading(false);
        if (res && res.code === 10000) {
            // console.log(res);
            const { data } = res;
            if (type === 'new_child_task') {
                setTaskDetail({
                    personalPrivacyFlag: data.personalPrivacyFlag,
                    parentPlanEndTime: data.planEndTime,
                    parentTaskId: data.id
                });
                setTaskObj({
                    executeEmployeeCode: getEmployeeCode() || '',
                    planStartTime: '',
                    planEndTime: data.planEndTime || '',
                    taskPriority: 1,
                    auditEmployeeCode: '',
                    acceptanceEmployeeCode: ''
                });
                return;
            }
            // if (type === 'copy_task' || type === 'restart_task') {
            if (type === 'copy_task') {
                data.cycleTaskFlag = 0;
                data.cycleTaskType = undefined;
                data.cycleTaskDayList = [];
                data.parentTaskId = '';
            }
            setTaskDetail(data);
            const {
                taskName: name,
                taskDesc: desc,
                executeEmployeeCode,
                planStartTime,
                planEndTime,
                taskPriority,
                auditEmployeeCode,
                acceptanceEmployeeCode,
                participantEmployeeCodeList,
                subtaskInfoCopyVOList = []
            } = data;
            setParticipantEmployeeList(participantEmployeeCodeList || []);
            form.setFieldsValue({
                taskName: name,
                participantEmployeeCodeList
            });
            setTaskName(name);
            const desc2 = BraftEditor.createEditorState(desc);
            editorRef.current.setValue(desc2);
            setTaskObj({
                executeEmployeeCode,
                planStartTime,
                planEndTime,
                taskPriority,
                auditEmployeeCode,
                acceptanceEmployeeCode
            });
            if (type !== 'change_task' && type !== 'restart_task' && subtaskInfoCopyVOList.length > 0) {
                setChildList(subtaskInfoCopyVOList);
            }
        }
    };

    const handleTreeSelect = val => {
        setParticipantEmployeeList(val);
    };

    // 上一级任务列表搜索
    const handleSearchParent = debounce(value => {
        getParentTaskList(value.trim());
    }, 200);

    const handleChangeParent = debounce(value => {
        if (value === undefined) {
            getParentTaskList();
        }
    }, 200);

    React.useEffect(() => {
        if (visible) {
            form.resetFields();
            setTaskName('');
            setTaskDetail(null);
            setParticipantEmployeeList([]);
            setParentTaskId(undefined);
            setEnableChildren(0);
            const desc2 = BraftEditor.createEditorState('');
            if (editorRef.current) {
                editorRef.current.setValue(desc2);
            }
            setTaskObj({
                executeEmployeeCode: getEmployeeCode() || '',
                planStartTime: '',
                planEndTime: '',
                taskPriority: 1,
                auditEmployeeCode: '',
                acceptanceEmployeeCode: ''
            });
            setChildList([]);
            setIsCheck(false);
            setIsMore(false);
            // console.log(type, record);
            if (type && record) {
                getActionTaskDetail(record.id);
            }
        }
    }, [visible]);

    React.useEffect(() => {
        if (type === 'change_task' && taskDetail && taskDetail.parentTaskId) {
            getParentTaskList();
        }
    }, [taskDetail]);

    React.useEffect(() => {
        getEmployeeListAsync(user.companyId);
        // getEmployeeListAsync();
    }, [user.companyId]);
    const controls = [
        'undo',
        'redo',
        // 'separator',
        'font-size',
        // 'line-height',
        // 'letter-spacing',
        // 'separator',
        'text-color',
        'bold',
        'italic',
        'underline',
        'strike-through',
        // 'separator',
        // 'superscript',
        // 'subscript',
        // 'remove-styles',
        // 'emoji',
        // 'separator',
        'text-indent',
        'text-align',
        // 'separator',
        // 'headings',
        'list-ul',
        'list-ol',
        // 'blockquote',
        // 'code',
        // 'separator',
        'media',
        // 'link',
        'hr',
        // 'separator',
        'clear'
    ];

    return (
        <Modal
            title={getTitle()}
            className={styles.startTask}
            wrapClassName={styles.startModal}
            width={900}
            okText="提交"
            visible={visible}
            confirmLoading={confirmLoading}
            onOk={handleOk}
            destroyOnClose
            keyboard={false}
            maskClosable={false}
            onCancel={handleCancel}
            afterClose={handleAfterClose}
        >
            <Spin spinning={loading}>
                <div style={{ padding: '0 20px' }}>
                    {type === 'new_child_task' && (
                        <div className={styles.parentTask}>
                            <div className={styles.taskTitle}>上一级任务：</div>
                            <div className={styles.taskValue}>
                                {record.taskName || ''}
                                {/* <a
                                onClick={e => {
                                    e.preventDefault();
                                    setVisible(false);
                                    history.push({
                                        pathname: '/work/task/taskdetail',
                                        query: { id: record.id || '' },
                                        state: { tabRoute: true }
                                    });
                                }}
                            >
                                {record.taskName || ''}
                            </a> */}
                            </div>
                        </div>
                    )}
                    {type === 'change_task' && taskObj && taskObj.auditEmployeeCode && (
                        <div className={styles.parentTask}>
                            温馨提示：变更执行人、截止时间、验收人字段需审核，其余无需审核；
                        </div>
                    )}
                    {type === 'restart_task' && record.launchAuditFlag && (
                        <div className={styles.parentTask} style={{ color: '#f5222d' }}>
                            温馨提示：当前任务审核不通过，请确认内容并重新提交
                        </div>
                    )}
                    {type === 'change_task' && taskDetail && taskDetail.parentTaskId && (
                        <div
                            style={{
                                position: 'relative',
                                display: 'flex',
                                height: 40,
                                alignItems: 'center',
                                margin: '6px 0 0',
                                cursor: 'pointer'
                            }}
                            title="上一级任务"
                        >
                            <div
                                style={{
                                    position: 'absolute',
                                    left: 0,
                                    top: '50%',
                                    transform: 'translateY(-50%)',
                                    padding: '0 10px',
                                    zIndex: 0
                                }}
                            >
                                <Icon type="cluster" />
                            </div>
                            <Form.Item style={{ display: 'block', flex: 1 }}>
                                {getFieldDecorator('parentTaskId', {
                                    rules: [
                                        {
                                            required: true,
                                            message: '请选择上一级任务'
                                        }
                                    ],
                                    initialValue: (taskDetail && taskDetail.parentTaskId) || undefined
                                })(
                                    <Select
                                        placeholder="请选择上一级任务"
                                        allowClear
                                        showSearch
                                        className={styles.upTask}
                                        style={{ display: 'block', flex: 1 }}
                                        dropdownStyle={{ maxHeight: 250, overflow: 'auto' }}
                                        getPopupContainer={trigger => trigger.parentNode}
                                        onSearch={handleSearchParent}
                                        onChange={handleChangeParent}
                                        filterOption={false}
                                        showArrow={false}
                                        optionLabelProp="label"
                                    >
                                        {parentTaskList.map(item => (
                                            <Option key={item.taskId} value={item.taskId} label={item.taskName}>
                                                <TaskListItem data={item} />
                                            </Option>
                                        ))}
                                        {parentTaskList && parentTaskList.length > 0 && (
                                            <Option key="tips" value={undefined} label="" disabled>
                                                更多数据请输入关键字模糊搜索
                                            </Option>
                                        )}
                                    </Select>
                                )}
                            </Form.Item>
                        </div>
                    )}
                    <Form.Item>
                        {getFieldDecorator('taskName', {
                            initialValue: '',
                            rules: [
                                {
                                    required: true,
                                    message: ' '
                                },
                                {
                                    whitespace: true,
                                    message: ''
                                }
                            ]
                        })(
                            <Input
                                placeholder="请输入任务名称"
                                maxLength={200}
                                onChange={handleNameChange}
                                allowClear
                            />
                        )}
                    </Form.Item>
                    <QuickTaskBar
                        employeeList={employeeList}
                        isCheck={isCheck}
                        onChange={handleTaskChange}
                        {...taskObj}
                        taskType={type}
                        // parentEndTime={taskDetail ? taskDetail.parentPlanEndTime : undefined}
                        cycleTaskFlag={taskDetail ? taskDetail.cycleTaskFlag : undefined}
                        acceptanceStatus={taskDetail ? taskDetail.acceptanceStatus : undefined}
                        auditStatus={taskDetail ? taskDetail.auditStatus : undefined}
                        taskStatus={taskDetail ? taskDetail.taskStatus : undefined}
                    />
                    <BraftEditor
                        ref={editorRef}
                        onChange={handleEditorChange}
                        media={{
                            uploadFn: myUploadFn,
                            validateFn: myValidateFn,
                            accepts: {
                                image: 'image/png,image/jpeg,image/gif'
                            }
                        }}
                        controls={controls}
                        excludeControls={['fullscreen']}
                        imageControls={[
                            {
                                onClick: block => {
                                    console.log(block);
                                } // 指定控件点击后的回调，参数为当前图片的block对象
                            },
                            'align-left',
                            'align-center',
                            'align-right',
                            'size',
                            'remove'
                        ]}
                        placeholder="请输入任务描述"
                        className={styles.customBraftEditor}
                        contentStyle={{ height: 120 }}
                        style={{
                            border: '1px solid #d9d9d9',
                            borderTopWidth: '1.02px',
                            borderRadius: '4px',
                            marginTop: '4px'
                        }}
                    />
                    {!(taskDetail && taskDetail.cycleTaskFlag) && (
                        <div
                            style={{
                                position: 'relative',
                                display: 'flex',
                                height: 40,
                                alignItems: 'center',
                                margin: '10px 0 0',
                                cursor: 'pointer'
                            }}
                            title="参与人"
                        >
                            <div
                                style={{
                                    position: 'absolute',
                                    left: 0,
                                    top: '50%',
                                    transform: 'translateY(-50%)',
                                    padding: '0 10px',
                                    zIndex: 0
                                }}
                            >
                                <Icon type="user" />
                            </div>
                            <TreeSelect
                                multiple
                                allowClear
                                showSearch
                                maxTagCount={8}
                                className={styles.participant}
                                value={participantEmployeeList}
                                style={{ display: 'block', flex: 1 }}
                                placeholder="请选择参与人"
                                dropdownClassName={styles.treeSelectDropDown}
                                dropdownStyle={{ maxHeight: 250, overflow: 'auto' }}
                                getPopupContainer={trigger => trigger.parentNode}
                                treeNodeFilterProp="title"
                                treeData={employeeList}
                                onChange={handleTreeSelect}
                            ></TreeSelect>
                        </div>
                    )}
                    {(!type || (taskDetail && !taskDetail.parentTaskId)) && (
                        <Form.Item style={{ display: 'flex', justifyContent: 'flex-end' }}>
                            {getFieldDecorator('enableChildrenQueryFlag', {
                                valuePropName: 'checked',
                                initialValue: (taskDetail && taskDetail.enableChildrenQueryFlag) || false
                            })(<Checkbox>当前一级任务允许被下级所有子任务查阅</Checkbox>)}
                        </Form.Item>
                    )}
                    {type !== 'change_task' && type !== 'restart_task' && (
                        <ChildTask
                            type={type}
                            employeeList={employeeList}
                            taskList={childList}
                            isCheck={isCheck}
                            parentEndTime={
                                taskObj
                                    ? taskObj.planEndTime || (taskDetail ? taskDetail.parentPlanEndTime : undefined)
                                    : undefined
                            }
                            setIsCheck={setIsCheck}
                            onChange={handleChildListChange}
                        />
                    )}

                    <div className={styles.moreButton}>
                        <Button type="link" onClick={handleMore}>
                            更多信息
                            <Icon type="down" />
                        </Button>
                    </div>
                </div>
            </Spin>
        </Modal>
    );
};

export default connect()(Form.create()(StartTaskModal));
